home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / AtlantisBus.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  7.0 KB  |  236 lines

  1. class AtlantisBus extends MovingObject
  2. {
  3.    var mcRef;
  4.    var bKeyEasterPressed;
  5.    var nKeyMoveUp;
  6.    var nKeyMoveDown;
  7.    var nKeyMoveLeft;
  8.    var nKeyMoveRight;
  9.    var nMovement;
  10.    var nCurrentDir;
  11.    static var sLINKAGE_NAME = "mcAtlantisBus";
  12.    static var nMOVE_UP = Key.UP;
  13.    static var nMOVE_DOWN = Key.DOWN;
  14.    static var nMOVE_LEFT = Key.LEFT;
  15.    static var nMOVE_RIGHT = Key.RIGHT;
  16.    static var nNO_KEY = -99;
  17.    static var nEASTER_EGG = 83;
  18.    static var nSPEED = 1;
  19.    static var nINITIAL_X = 10;
  20.    static var nINITIAL_Y = 170;
  21.    function AtlantisBus()
  22.    {
  23.       super(CTRLGame.getRef().mcRef.attachMovie(AtlantisBus.sLINKAGE_NAME,AtlantisBus.sLINKAGE_NAME,CTRLGame.getRef().calculateDepth(AtlantisBus.nINITIAL_Y,CTRLGame.nBUS_ADD)));
  24.       this.mcRef._x = AtlantisBus.nINITIAL_X;
  25.       this.mcRef._y = AtlantisBus.nINITIAL_Y;
  26.       this.bKeyEasterPressed = false;
  27.       if(!Main.getRef().EasterEgg)
  28.       {
  29.          this.nKeyMoveUp = AtlantisBus.nMOVE_UP;
  30.          this.nKeyMoveDown = AtlantisBus.nMOVE_DOWN;
  31.          this.nKeyMoveLeft = AtlantisBus.nMOVE_LEFT;
  32.          this.nKeyMoveRight = AtlantisBus.nMOVE_RIGHT;
  33.       }
  34.       else
  35.       {
  36.          this.nKeyMoveUp = AtlantisBus.nMOVE_DOWN;
  37.          this.nKeyMoveDown = AtlantisBus.nMOVE_UP;
  38.          this.nKeyMoveLeft = AtlantisBus.nMOVE_RIGHT;
  39.          this.nKeyMoveRight = AtlantisBus.nMOVE_LEFT;
  40.       }
  41.    }
  42.    function cleanUp()
  43.    {
  44.       super.cleanUp();
  45.       this.mcRef.swapDepths(7777);
  46.       this.mcRef.removeMovieClip();
  47.    }
  48.    function doUnPause()
  49.    {
  50.       if(!CTRLGame.getRef().Screen.isInMiniGame())
  51.       {
  52.          super.doUnPause();
  53.       }
  54.    }
  55.    function resumeAnim()
  56.    {
  57.       super.doUnPause();
  58.    }
  59.    function checkObjects()
  60.    {
  61.       CTRLGame.getRef().checkPowerUps();
  62.       CTRLGame.getRef().checkAlgaes();
  63.       CTRLGame.getRef().checkJellys();
  64.       CTRLGame.getRef().checkDirtWalls();
  65.       CTRLGame.getRef().checkFinish();
  66.    }
  67.    function manageMovement()
  68.    {
  69.       this.setupKeys();
  70.       if(this.canMove() && this.nMovement == 0)
  71.       {
  72.          var _loc2_ = this.nCurrentDir;
  73.          if(Key.isDown(this.nKeyMoveUp))
  74.          {
  75.             if(this.isNextMoveGood(CTRLGame.nDIR_UP))
  76.             {
  77.                this.setState(MovingObject.sSTATE_UP);
  78.                this.nCurrentDir = CTRLGame.nDIR_UP;
  79.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  80.             }
  81.          }
  82.          else if(Key.isDown(this.nKeyMoveDown))
  83.          {
  84.             if(this.isNextMoveGood(CTRLGame.nDIR_DOWN))
  85.             {
  86.                this.setState(MovingObject.sSTATE_DOWN);
  87.                this.nCurrentDir = CTRLGame.nDIR_DOWN;
  88.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  89.             }
  90.          }
  91.          else if(Key.isDown(this.nKeyMoveLeft))
  92.          {
  93.             if(this.isNextMoveGood(CTRLGame.nDIR_LEFT))
  94.             {
  95.                this.setState(MovingObject.sSTATE_LEFT);
  96.                this.nCurrentDir = CTRLGame.nDIR_LEFT;
  97.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  98.             }
  99.          }
  100.          else if(Key.isDown(this.nKeyMoveRight))
  101.          {
  102.             if(this.isNextMoveGood(CTRLGame.nDIR_RIGHT))
  103.             {
  104.                this.setState(MovingObject.sSTATE_RIGHT);
  105.                this.nCurrentDir = CTRLGame.nDIR_RIGHT;
  106.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  107.             }
  108.          }
  109.          if(this.nMovement == 0)
  110.          {
  111.             switch(this.nCurrentDir)
  112.             {
  113.                case CTRLGame.nDIR_UP:
  114.                   this.setState(MovingObject.sSTATE_IDLE_UP);
  115.                   break;
  116.                case CTRLGame.nDIR_DOWN:
  117.                   this.setState(MovingObject.sSTATE_IDLE_DOWN);
  118.                   break;
  119.                case CTRLGame.nDIR_LEFT:
  120.                   this.setState(MovingObject.sSTATE_IDLE_LEFT);
  121.                   break;
  122.                case CTRLGame.nDIR_RIGHT:
  123.                   this.setState(MovingObject.sSTATE_IDLE_RIGHT);
  124.             }
  125.          }
  126.          CTRLGame.getRef().Screen.manageAnim(this.nCurrentDir,_loc2_,this.nMovement);
  127.       }
  128.    }
  129.    function setupKeys()
  130.    {
  131.       if(this.canMove())
  132.       {
  133.          if(!Key.isDown(AtlantisBus.nEASTER_EGG))
  134.          {
  135.             this.bKeyEasterPressed = false;
  136.          }
  137.          else if(Key.isDown(AtlantisBus.nEASTER_EGG) && (!Main.getRef().EasterEgg && !this.bKeyEasterPressed))
  138.          {
  139.             Main.getRef().setEasterEgg(true);
  140.             this.bKeyEasterPressed = true;
  141.             this.nKeyMoveUp = AtlantisBus.nMOVE_DOWN;
  142.             this.nKeyMoveDown = AtlantisBus.nMOVE_UP;
  143.             this.nKeyMoveLeft = AtlantisBus.nMOVE_RIGHT;
  144.             this.nKeyMoveRight = AtlantisBus.nMOVE_LEFT;
  145.          }
  146.          else if(Key.isDown(AtlantisBus.nEASTER_EGG) && (Main.getRef().EasterEgg && !this.bKeyEasterPressed))
  147.          {
  148.             Main.getRef().setEasterEgg(false);
  149.             this.bKeyEasterPressed = true;
  150.             this.nKeyMoveUp = AtlantisBus.nMOVE_UP;
  151.             this.nKeyMoveDown = AtlantisBus.nMOVE_DOWN;
  152.             this.nKeyMoveLeft = AtlantisBus.nMOVE_LEFT;
  153.             this.nKeyMoveRight = AtlantisBus.nMOVE_RIGHT;
  154.          }
  155.       }
  156.    }
  157.    function isNextMoveGood(_nNextDir)
  158.    {
  159.       var _loc3_ = this.getWishMidPos(_nNextDir);
  160.       var _loc4_ = false;
  161.       if(this.isTrackOkay(_nNextDir) && !CTRLGame.getRef().isTouchingWall(_loc3_.x,_loc3_.y))
  162.       {
  163.          _loc4_ = true;
  164.       }
  165.       return _loc4_;
  166.    }
  167.    function adaptDepth()
  168.    {
  169.       this.mcRef.swapDepths(CTRLGame.getRef().calculateDepth(this.mcRef._y,CTRLGame.nBUS_ADD));
  170.    }
  171.    function manageIdle()
  172.    {
  173.       this.manageMovement();
  174.       CTRLGame.getRef().checkJellys();
  175.       CTRLGame.getRef().checkAlgaes();
  176.    }
  177.    function IdleUp()
  178.    {
  179.       this.manageIdle();
  180.    }
  181.    function IdleDown()
  182.    {
  183.       this.manageIdle();
  184.    }
  185.    function IdleLeft()
  186.    {
  187.       this.manageIdle();
  188.    }
  189.    function IdleRight()
  190.    {
  191.       this.manageIdle();
  192.    }
  193.    function Left()
  194.    {
  195.       if(this.nMovement > 0 && this.canMove())
  196.       {
  197.          this.mcRef._x -= AtlantisBus.nSPEED;
  198.          this.nMovement -= AtlantisBus.nSPEED;
  199.          this.checkObjects();
  200.       }
  201.       this.manageMovement();
  202.    }
  203.    function Up()
  204.    {
  205.       if(this.nMovement > 0 && this.canMove())
  206.       {
  207.          this.mcRef._y -= AtlantisBus.nSPEED;
  208.          this.nMovement -= AtlantisBus.nSPEED;
  209.          this.adaptDepth();
  210.          this.checkObjects();
  211.       }
  212.       this.manageMovement();
  213.    }
  214.    function Right()
  215.    {
  216.       if(this.nMovement > 0 && this.canMove())
  217.       {
  218.          this.mcRef._x += AtlantisBus.nSPEED;
  219.          this.nMovement -= AtlantisBus.nSPEED;
  220.          this.checkObjects();
  221.       }
  222.       this.manageMovement();
  223.    }
  224.    function Down()
  225.    {
  226.       if(this.nMovement > 0 && this.canMove())
  227.       {
  228.          this.mcRef._y += AtlantisBus.nSPEED;
  229.          this.nMovement -= AtlantisBus.nSPEED;
  230.          this.adaptDepth();
  231.          this.checkObjects();
  232.       }
  233.       this.manageMovement();
  234.    }
  235. }
  236.